/**
 * @author Glan.duanyj
 * @date 2014-05-12
 * @project rest_demo
 */
package com.baiduspring.function.ucpass;

import com.baiduspring.function.ucpass.client.AbsRestClient;
import com.baiduspring.function.ucpass.client.JsonReqClient;
import com.baiduspring.function.ucpass.client.XmlReqClient;

import java.io.IOException;

public class RestTest {
	private String accountSid;
	private String authToken;
	
	public String getAccountSid() {
		return accountSid;
	}
	public void setAccountSid(String accountSid) {
		this.accountSid = accountSid;
	}
	public String getAuthToken() {
		return authToken;
	}
	public void setAuthToken(String authToken) {
		this.authToken = authToken;
	}
	static AbsRestClient InstantiationRestAPI(boolean enable) {
		if(enable) {
			return new JsonReqClient();
		} else {
			return new XmlReqClient();
		}
	}
	public static void testFindAccount(boolean json,String accountSid,String authToken){
		try {
			String result=InstantiationRestAPI(json).findAccoutInfo(accountSid, authToken);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testCreateClient(boolean json,String accountSid,String authToken,String appId,String clientName
			,String chargeType,String charge,String mobile){
		try {
			String result=InstantiationRestAPI(json).createClient(accountSid, authToken, appId, clientName, chargeType, charge,mobile);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testfindClients(boolean json,String accountSid,String authToken,String appId,String start
			,String limit){
		try {
			String result=InstantiationRestAPI(json).findClients(accountSid, authToken, appId, start, limit);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testfindClientByNbr(boolean json,String accountSid,String authToken,String clientNumber,String appId){
		try {
			String result=InstantiationRestAPI(json).findClientByNbr(accountSid, authToken, clientNumber,appId);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testCloseClient(boolean json,String accountSid,String authToken,String clientNumber,String appId){
		try {
			String result=InstantiationRestAPI(json).closeClient(accountSid, authToken, clientNumber,appId);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testChargeClient(boolean json,String accountSid,String authToken,String clientNumber,
			String chargeType,String charge,String appId){
		try {
			String result=InstantiationRestAPI(json).charegeClient(accountSid, authToken, clientNumber, chargeType, charge,appId);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testBillList(boolean json,String accountSid,String authToken,String appId,String date){
		try {
			String result=InstantiationRestAPI(json).billList(accountSid, authToken, appId, date);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testClientBillList(boolean json,String accountSid,String authToken,String appId,String clientNumber,String date){
		try {
			String result=InstantiationRestAPI(json).clientBillList(accountSid, authToken, appId, clientNumber, date);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testCallback(boolean json,String accountSid,String authToken,String appId,String fromClient,String to,String fromSerNum,String toSerNum){
		try {
			String result=InstantiationRestAPI(json).callback(accountSid, authToken, appId, fromClient, to,fromSerNum,toSerNum);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testVoiceCode(boolean json,String accountSid,String authToken,String appId,String to,String verifyCode){
		try {
			String result=InstantiationRestAPI(json).voiceCode(accountSid, authToken, appId, to, verifyCode);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testTemplateSMS(boolean json,String accountSid,String authToken,String appId,String templateId,String to,String param){
		try {
			String result=InstantiationRestAPI(json).templateSMS(accountSid, authToken, appId, templateId, to, param);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	public static void testfindClientByMobile(boolean json,String accountSid,String authToken,String mobile,String appId){
		try {
			String result=InstantiationRestAPI(json).findClientByMobile(accountSid, authToken, mobile, appId);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static void testDispalyNumber(boolean json,String accountSid,String authToken,String appId,String clientNumber,String display){
		try {
			String result=InstantiationRestAPI(json).dispalyNumber(accountSid, authToken, appId, clientNumber, display);
			System.out.println("Response content is: " + result);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	/**
	 * 测试说明 参数顺序，请参照各具体方法参数名称
	 * 参数名称含义，请参考rest api 文档
	 * @author Glan.duanyj
	 * @date 2014-06-30
	 * @return void
	 * @throws IOException 
	 * @method main
	 */
//	public static void main(String[] args) throws IOException {
////		String jsonStr="{\"client\":\"1\"}";
////		JSONObject obj=JSONObject.fromObject(jsonStr);
////		System.out.println(obj.getInt("client"));
//		System.out.println("请输入参数，以空格隔开...");
//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		String param=br.readLine();
//		String [] params=param.split(" ");
//		String method = params[0];
//		boolean json=true;
//		if (params[1].equals("xml")) {
//			json=false;
//		}
//		if (method.equals("1")) {
//			String accountSid="";
//			String token="";
//			testFindAccount(json,accountSid,token);
//		}else if (method.equals("2")) {
//			testCreateClient(json, params[2],params[3], params[4], params[5], params[6], params[7], params[8]);
//		}else if (method.equals("3")) {
//			String accountSid="";
//			String token="";
//			String appId="";
//			testfindClients(json,accountSid,token,appId,"0","5");
//		}else if (method.equals("4")) {
//			testfindClientByNbr(json,params[2],params[3], params[4], params[5]);
//		}else if (method.equals("5")) {
//			testCloseClient(json, params[2],params[3], params[4], params[5]);
//		}else if (method.equals("6")) {
//			testChargeClient(json, params[2],params[3], params[4], params[5], params[6], params[7]);
//		}else if (method.equals("7")) {
//			testBillList(json, params[2], params[3],params[4], params[5]);
//		}else if (method.equals("8")) {
//			testClientBillList(json, params[2], params[3],params[4],params[5], params[6]);
//		}else if (method.equals("9")) {
//			String accountSid = "";// 主账户Id
//			String authToken="";
//			String appId="";
//			accountSid="";
//			authToken="";
//			appId="";
//			String fromClient="";
//			String to="";
//			String fromSerNum="";
//			String toSerNum="";
//			testCallback(json, accountSid, authToken, appId, fromClient, to, fromSerNum, toSerNum);
//		}else if (method.equals("10")) {
//			String to="";
//			String accountSid="";
//			String token="";
//			String appId="";
//			String para = "";
//			testVoiceCode(json, accountSid, token, appId, to, para);
//		}else if (method.equals("11")) { //短信验证码 
//			String accountSid="";
//			String token="";
//			String appId="";
//			String templateId="";
//			String to="";
//			String para="";
//			testTemplateSMS(json, accountSid,token,appId, templateId,to,para);
//		}else if (method.equals("12")) {
//			testfindClientByMobile(json, params[2],params[3], params[4], params[5]);
//		}else if (method.equals("13")) {
//			String accountSid="";
//			String token="";
//			String clientNumber="";
//			String appId="";
//			String display="1";
//			testDispalyNumber(json, accountSid, token, appId, clientNumber, display);
//		}
//	}
	
	
	
	
	
	
	public String send() {
//		Properties properties = new Properties();
////		InputStream in = ClassLoader.getSystemResourceAsStream("/ucpaas.config.properties");
//		InputStream in = getClass().getResourceAsStream("/ucpaas.config.properties");
//		try {
//			properties.load(in);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		
//		String accountSid = properties.getProperty("accountSid");
//		String token = properties.getProperty("token");
//		String appId = properties.getProperty("appId");
//		String accountSid = "ef3f5af0ba993a3083b6af3883dbef66";
//		String token = "08cbe34855d1e2c7a42ecf63e84eef1a";
//		String appId = "db5e15cfcb9e4814a41795194561b10a";
		String templateId = "45352";
		String to = "18781981959,18310588722";
		String param = "123456,3";
//		try {
//			String result = InstantiationRestAPI(true).templateSMS(accountSid, token, appId, templateId, to, param);
//			System.out.println("Response content is: " + result);
//			return result;
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return null;
//		UCPaasSmsUtil util = new UCPaasSmsUtil();
//		return util.send(templateId, to, param);
		
		return SmsUtil.getInstance().send(templateId, to, param);
	}
	
	public static void main(String[] args) {
		RestTest restTest = new RestTest();
		restTest.send();
	}
	
	
	
	
	
	
	
	
	
}
